'''
Created on Mar 7, 2011

@author: User
'''
import unittest
from cliques.radixTree import RadixTree


class RadixTreeTester(unittest.TestCase):


    def setUp(self):
        self.fixture = RadixTree()


    def tearDown(self):
        self.fixture = None

    def testInsertEmpty(self):        
        foundItem = self.fixture.find("")        
        self.assertTrue(foundItem is None)

        self.fixture.insert("1",1)
        foundItem =  self.fixture.find("1")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,1)

        self.fixture.insert("",0)
        foundItem =  self.fixture.find("")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,0)

    def testInsertUpdateRoot(self):        
        self.fixture.insert("11",11)
        foundItem =  self.fixture.find("11")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,11)

        self.fixture.insert("12",12)
        foundItem =  self.fixture.find("12")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,12)
        
        self.fixture.insert("1",1)
        foundItem =  self.fixture.find("1")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,1)

    def testInsertNewRoot(self):
        self.fixture.insert("11",11)
        foundItem =  self.fixture.find("11")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,11)

        self.fixture.insert("111",111)
        foundItem =  self.fixture.find("111")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,111)
        
        self.fixture.insert("1",1)
        foundItem =  self.fixture.find("1")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,1)
        
        self.fixture.insert("",0)
        foundItem =  self.fixture.find("")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,0)

        
    def testInsertFind(self):
        foundItem = self.fixture.find("1")        
        self.assertTrue(foundItem is None)
        
        self.fixture.insert("1",1)
        foundItem =  self.fixture.find("1")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,1)
        
        self.fixture.insert("11",11)        
        foundItem =  self.fixture.find("11")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value, 11)

        self.fixture.insert("12",12)        
        foundItem =  self.fixture.find("12")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value,12)        

        self.fixture.insert("2",2)        
        foundItem =  self.fixture.find("2")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value, 2)

        foundItem =  self.fixture.find("1")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value, 1)
        foundItem =  self.fixture.find("11")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value, 11)
        foundItem =  self.fixture.find("12")
        self.assertTrue(foundItem is not None)
        self.assertEquals(foundItem.value, 12)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()